package dk.kapetanovic.jaft.action;


import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import dk.kapetanovic.jaft.transaction.Transaction;

public class OpenFileWriterAction extends OpenFileAction {
	
	private FileWriter writer;
	private boolean append;
	
	public OpenFileWriterAction(File file, boolean append, 
			Transaction transaction) {
		super(file, !append, transaction);
		this.append = append;
	}

	@Override
	public void close() throws IOException {
		if(writer != null)
			writer.close();
	}

	@Override
	public Object execute() throws IOException {
		writer = new FileWriter(original, append);
		return writer;
	}
}
